#!/usr/bin/env node

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

// 使用 sleep 函数
sleep(2000).then(() => {
  console.log('Hello');
});

sleep(2000).then(() => {
  console.log('World');
});



// 03-sleep.js
function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}

// 使用 sleep 函数
(async () => {
  await sleep(2000);
  console.log('Hello');
})();

(async () => {
  await sleep(2000);
  console.log('World');
})();



// 03-sleep.js
// 使用原生 Promise 版本的 setTimeout
(async () => {
  await new Promise(resolve => setTimeout(resolve, 2000));
  console.log('Hello');
})();

(async () => {
  await new Promise(resolve => setTimeout(resolve, 2000));
  console.log('World');
})();